home *** CD-ROM | disk | FTP | other *** search
/ Revista CD Expert 37 / CD Expert nº 37.iso / LastCall / lastcall.exe / stuff / lastcall.dxr / 00042_Utils.ls < prev    next >
Encoding:
Text File  |  2000-03-27  |  13.5 KB  |  544 lines

  1. on setVis flag
  2.   repeat with X = 1 to the lastChannel
  3.     sprite(X).visible = flag
  4.   end repeat
  5. end
  6.  
  7. on resetNewCharacterTimer
  8.   global gLastCharacterArrived
  9.   gLastCharacterArrived = now()
  10. end
  11.  
  12. on timeSinceLastCharacter
  13.   global gLastCharacterArrived
  14.   return elapsedTime(gLastCharacterArrived)
  15. end
  16.  
  17. on resetForcedCharacterTimer
  18.   global gLastCharacterForced, gForceNextCharacterAt
  19.   gLastCharacterForced = now()
  20.   gForceNextCharacterAt = randomBetween(currentLevel(#newCharacterMinInterval), currentLevel(#newCharacterMaxInterval))
  21. end
  22.  
  23. on timeSinceLastForcedCharacter
  24.   global gLastCharacterForced
  25.   return elapsedTime(gLastCharacterForced)
  26. end
  27.  
  28. on newCharNoSoonerThan interval
  29.   global gLastCharacterArrived
  30.   return gLastCharacterArrived = (currentLevel(#newCharacterMinInterval) - interval)
  31. end
  32.  
  33. on sumGameLevels thang, startLevel, endLevel
  34.   global gGameSetup, gGameLevel
  35.   sumIt = 0
  36.   if voidp(startLevel) then
  37.     startLevel = 1
  38.   end if
  39.   if voidp(endLevel) then
  40.     endLevel = gGameLevel
  41.   end if
  42.   repeat with gameLevel = startLevel to endLevel
  43.     sumIt = sumIt + gGameSetup[gameLevel][thang]
  44.   end repeat
  45.   return sumIt
  46. end
  47.  
  48. on checkElapsedTime
  49.   global gForceNextCharacterAt, gBarTopManager, gPauseState, gPlayerTips, gPearlyGates, gUserQuitFlag
  50.   if gPauseState then
  51.     exit
  52.   else
  53.     if inTestMode() then
  54.       exit
  55.     else
  56.       if inBonusMode() then
  57.         exit
  58.       else
  59.         if gPearlyGates then
  60.           exit
  61.         else
  62.           if gUserQuitFlag then
  63.             exit
  64.           else
  65.             if inMenuMode() then
  66.               exit
  67.             end if
  68.           end if
  69.         end if
  70.       end if
  71.     end if
  72.   end if
  73.   if not inRecipeMode() then
  74.     if (timeSinceLastForcedCharacter() > gForceNextCharacterAt) or (numberAtBar(gBarTopManager) = 0) then
  75.       if gPlayerTips = 0 then
  76.         resetForcedCharacterTimer()
  77.       else
  78.         if newCharacterEnters(#ifServed) then
  79.           resetForcedCharacterTimer()
  80.         end if
  81.       end if
  82.     end if
  83.   end if
  84.   repeat with X = 1 to numBarSlots()
  85.     sendSprite(barSlotToSprite(X), #timeElapsed)
  86.   end repeat
  87. end
  88.  
  89. on draggingBarTopGlass
  90.   global gWellSprite
  91.   if draggingWellThang() then
  92.     if isGlassIngredient(gWellSprite.pIngredient) then
  93.       return 1
  94.     end if
  95.   end if
  96.   return 0
  97. end
  98.  
  99. on draggingBottleThang
  100.   global gDraggingBottle
  101.   return gDraggingBottle
  102. end
  103.  
  104. on draggingBottleOrSpoon
  105.   return draggingBottleThang() or draggingSpoon()
  106. end
  107.  
  108. on draggingAnything
  109.   return draggingBottleThang() or draggingWellThang() or draggingSpoon()
  110. end
  111.  
  112. on draggingIngredient
  113.   return draggingBottleThang() or draggingWellThang()
  114. end
  115.  
  116. on draggingSpoon
  117.   global gSpoonSprite
  118.   dragging = gSpoonSprite[#pDragging]
  119.   if voidp(dragging) then
  120.     return 0
  121.   else
  122.     return dragging
  123.   end if
  124. end
  125.  
  126. on draggingWellThang
  127.   global gWellSprite
  128.   return gWellSprite.visible and (gWellSprite.memberNum > 0)
  129. end
  130.  
  131. on pourIt receiveSound
  132.   global gDraggingBottle
  133.   sendSprite(gDraggingBottle, #pour, sprite(gDraggingBottle).pIngredient, receiveSound)
  134. end
  135.  
  136. on fillVessel me, ingredient, liquidColor
  137.   if ingredient = #ice then
  138.     stopSoundFX()
  139.     message = sendSprite(me.pGlassIce, #mFillIce, me)
  140.   else
  141.     if isPowder(ingredient) then
  142.       if calcPowder(me.pContents) > 0 then
  143.         message = sendSprite(me.pGlassMask, #mFillLiquor, white(), me)
  144.       end if
  145.     else
  146.       message = sendSprite(me.pGlassMask, #mFillLiquor, liquidColor, me)
  147.     end if
  148.   end if
  149.   return message
  150. end
  151.  
  152. on buildVesselContentList inSprite, vesselName, default
  153.   pContents = inSprite.pContents
  154.   pContentString = inSprite.pContentString
  155.   if (pContentString = EMPTY) or voidp(pContentString) or (pContentString = default) then
  156.     pContentString = EMPTY
  157.     repeat with X = 1 to count(pContents)
  158.       ingredient = getPropAt(pContents, X)
  159.       cat = getCategory(ingredient)
  160.       if ((cat >= 1) and (cat <= 9)) or (cat = 16) then
  161.         if pContentString = EMPTY then
  162.           if vesselName = #beer then
  163.             vesselName = EMPTY
  164.           else
  165.             vesselName = getShortName(vesselName) && "Contents:" & RETURN
  166.           end if
  167.           pContentString = SPACE & vesselName
  168.         end if
  169.         addText = getDosage(ingredient, pContents[X], inSprite) & TAB & getMediumName(ingredient)
  170.         pContentString = pContentString && addText & RETURN
  171.       end if
  172.     end repeat
  173.     delete char -30000 of pContentString
  174.   end if
  175.   if (pContentString = EMPTY) or voidp(pContentString) then
  176.     pContentString = default
  177.   end if
  178.   return pContentString
  179. end
  180.  
  181. on numBarSlots
  182.   global gBarTopManager
  183.   return mGetNumBarSlots(gBarTopManager)
  184. end
  185.  
  186. on testLabels
  187.   global debug
  188.   debug = 1
  189.   go("testflash")
  190.   repeat with X = 1 to 8
  191.     getFlashLabels(script(35), X, 0)
  192.   end repeat
  193.   debug = 0
  194. end
  195.  
  196. on clearRecipe barSlot, ensureWindow
  197.   setRecipePatronName(barSlot, "No Patron")
  198.   setRecipeDrinkName(barSlot, "No Drink")
  199.   refreshRecipeWindow(ensureWindow)
  200. end
  201.  
  202. on mergeColors foo
  203.   rbuf = 0
  204.   gbuf = 0
  205.   bbuf = 0
  206.   numCol = count(foo)
  207.   if numCol = 0 then
  208.     return rgb(0, 0, 0)
  209.   end if
  210.   repeat with i = 1 to numCol
  211.     goo = foo[i]
  212.     thisColor = goo[1]
  213.     weight = goo[2]
  214.     rbuf = rbuf + (weight * (255 - thisColor.red))
  215.     gbuf = gbuf + (weight * (255 - thisColor.green))
  216.     bbuf = bbuf + (weight * (255 - thisColor.blue))
  217.   end repeat
  218.   rbuf = 255 - float(rbuf)
  219.   gbuf = 255 - float(gbuf)
  220.   bbuf = 255 - float(bbuf)
  221.   return rgb(rbuf, gbuf, bbuf)
  222. end
  223.  
  224. on weightedRGBofLiquids pContents
  225.   weightedList = []
  226.   totalQuantity = calcLiquidContents(pContents)
  227.   if totalQuantity = 0 then
  228.     return []
  229.   end if
  230.   repeat with X = 1 to count(pContents)
  231.     thisOne = getPropAt(pContents, X)
  232.     cat = getCategory(thisOne)
  233.     if getOne([2, 4, 5, 6, 7, 8, 16], cat) then
  234.       add(weightedList, [getLiquidColor(thisOne), float(pContents[X]) / totalQuantity])
  235.     end if
  236.   end repeat
  237.   return weightedList
  238. end
  239.  
  240. on calcTheseContents pContents, catList
  241.   global gTspPerOunce
  242.   totalQuantity = 0
  243.   repeat with X = 1 to count(pContents)
  244.     thisOne = getPropAt(pContents, X)
  245.     cat = getCategory(thisOne)
  246.     if getOne(catList, cat) then
  247.       if cat = 7 then
  248.         totalQuantity = totalQuantity + (pContents[X] / gTspPerOunce)
  249.         next repeat
  250.       end if
  251.       totalQuantity = totalQuantity + pContents[X]
  252.     end if
  253.   end repeat
  254.   return max(0, totalQuantity)
  255. end
  256.  
  257. on calcContents pContents
  258.   return calcTheseContents(pContents, [1, 2, 3, 4, 5, 6, 8, 16]) + calcPowder(pContents)
  259. end
  260.  
  261. on calcPowder pContents, tspToSubtract
  262.   global gTspPerOunce
  263.   powders = calcTheseContents(pContents, [7])
  264.   if voidp(tspToSubtract) then
  265.     tspToSubtract = 2.0
  266.   end if
  267.   return max(0, powders - (tspToSubtract / gTspPerOunce))
  268. end
  269.  
  270. on calcEmpty pContents
  271.   return calcTheseContents(pContents, [1, 2, 3, 4, 5, 6, 7, 8, 16]) = 0
  272. end
  273.  
  274. on calcLiquidContents pContents
  275.   return calcTheseContents(pContents, [2, 3, 4, 5, 6, 8, 16]) + calcPowder(pContents)
  276. end
  277.  
  278. on calcPourableContents pContents
  279.   pourable = calcTheseContents(pContents, [2, 3, 4, 5, 6, 8]) + calcPowder(pContents)
  280.   if pourable > 0 then
  281.     return pourable
  282.   else
  283.     if voidp(pContents[#Slush]) then
  284.       return 0
  285.     else
  286.       return pContents[#Slush]
  287.     end if
  288.   end if
  289. end
  290.  
  291. on countStirrableIngredients pContents
  292.   return countIngredients(pContents, [1, 2, 3, 4, 5, 6, 7, 8, 16])
  293. end
  294.  
  295. on countIngredients pContents, catList
  296.   stirCount = 0
  297.   repeat with X = 1 to count(pContents)
  298.     thisOne = getPropAt(pContents, X)
  299.     cat = getCategory(thisOne)
  300.     if getOne(catList, cat) then
  301.       stirCount = stirCount + 1
  302.     end if
  303.   end repeat
  304.   return max(0, stirCount)
  305. end
  306.  
  307. on calcLiquorContents pContents
  308.   return calcTheseContents(pContents, [2, 6, 8]) + (calcTheseContents(pContents, [3]) * 2.0)
  309. end
  310.  
  311. on calcWimpyContents pContents
  312.   return calcTheseContents(pContents, [4, 5])
  313. end
  314.  
  315. on addIce iceSprite, masterSprite, maxIceUnits, newMember, iceSound
  316.   if iceSprite.pIceAmount = maxIceUnits then
  317.     alertBeep()
  318.     return 0
  319.   else
  320.     pIceToAdd = iceSprite.pIcePerScoop
  321.     roomNeeded = mIsHoldingVolume(masterSprite) + pIceToAdd - masterSprite.pCapacity
  322.     if roomNeeded > 0.001 then
  323.       pIceToAdd = min(pIceToAdd, masterSprite.pCapacity - mIsHoldingVolume(masterSprite))
  324.     end if
  325.   end if
  326.   if voidp(masterSprite.pContents[#ice]) then
  327.     masterSprite.pContents[#ice] = pIceToAdd
  328.   else
  329.     masterSprite.pContents[#ice] = masterSprite.pContents[#ice] + pIceToAdd
  330.   end if
  331.   iceSprite.pIceAmount = iceSprite.pIceAmount + 1
  332.   if not voidp(newMember) then
  333.     iceSprite.member = newMember
  334.   end if
  335.   soundFX(iceSound, 1, 1)
  336.   sendSprite(masterSprite.pGlassMask, #mUpdateLiquidLevel, masterSprite)
  337.   return 1
  338. end
  339.  
  340. on fillIt pSpr, liquidColor, maskMember, maskLimit, masterSprite
  341.   global gPixelList
  342.   capacity = masterSprite.pCapacity
  343.   affectedByIce = masterSprite.pContents[#ice]
  344.   if affectedByIce = VOID then
  345.     affectedByIce = 0
  346.   end if
  347.   maskStart = masterSprite.pGlassMask.pMaskStart
  348.   currentQuantity = sendSprite(masterSprite.spriteNum, #mIsHoldingLiquid)
  349.   pContents = masterSprite.pContents
  350.   if count(pContents) then
  351.     if currentQuantity > 0 then
  352.       sprite(masterSprite.pGlassMask).color = mergeColors(weightedRGBofLiquids(pContents))
  353.     else
  354.       sprite(masterSprite.pGlassMask).color = black()
  355.     end if
  356.   else
  357.     if not voidp(liquidColor) then
  358.       sprite(masterSprite.pGlassMask).color = liquidColor
  359.     end if
  360.   end if
  361.   a = maskMember.regPoint
  362.   X = a.locH
  363.   pixelsPerOunce = gPixelList[masterSprite.pGlassType]
  364.   if masterSprite.pGlassType = #cocktail then
  365.     stuff = currentQuantity * 3.81999999999999984
  366.     height = power(stuff, 1 / 3.0)
  367.     if currentQuantity = 0 then
  368.       pixelsPerOunce = 1
  369.     else
  370.       pixelsPerOunce = height / currentQuantity * 6.5
  371.     end if
  372.   end if
  373.   if currentQuantity < affectedByIce then
  374.     Y = maskStart + (currentQuantity * pixelsPerOunce * 2)
  375.   else
  376.     Y = maskStart + (affectedByIce * pixelsPerOunce * 2) + ((currentQuantity - affectedByIce) * pixelsPerOunce)
  377.   end if
  378.   if Y > maskLimit then
  379.     maskMember.regPoint = point(X, maskLimit)
  380.     return 0
  381.   else
  382.     maskMember.regPoint = point(X, Y)
  383.     return 1
  384.   end if
  385. end
  386.  
  387. on forceRecipeSelection newRecipeID
  388.   if inRecipeMode() then
  389.     sendSprite(barSlotToSprite(2), #mForceRecipe, newRecipeID)
  390.   end if
  391. end
  392.  
  393. on togglePourClockText direction, onFlag
  394.   global gDrinkContentSpr
  395.   sendSprite(gDrinkContentSpr, #mRepositionSelf, direction, onFlag)
  396. end
  397.  
  398. on setPourClockText tipText, Force
  399.   global gDrinkContentSpr
  400.   sendSprite(gDrinkContentSpr, #mShowDrinkContents, tipText, Force)
  401. end
  402.  
  403. on formatBirthDate convertDate
  404.   return "DOB:" && formatDate(convertDate)
  405. end
  406.  
  407. on formatExpirationDate expDate
  408.   if voidp(expDate) then
  409.     expDate = randomDateInFuture()
  410.   end if
  411.   return "Expires:" && expDate
  412. end
  413.  
  414. on randomDateInFuture
  415.   today = systemDate()
  416.   return formatDate(date(today.year + random(3), random(12), random(31)))
  417. end
  418.  
  419. on formatDate convertDate
  420.   month = string(convertDate.month)
  421.   day = string(convertDate.day)
  422.   year = convertDate.year
  423.   century = year / 100
  424.   if length(day) < 2 then
  425.     put "0" before month
  426.   end if
  427.   if length(month) < 2 then
  428.     put "0" before month
  429.   end if
  430.   year = year - (century * 100)
  431.   year = string(year)
  432.   if length(year) < 2 then
  433.     put "0" before month
  434.   end if
  435.   return month & "/" & day & "/" & year
  436. end
  437.  
  438. on checkAge inDate, birthDate, yearsOfAge
  439.   myDate = inDate
  440.   inYear = inDate.year
  441.   if (inDate - birthDate) >= (date(inYear + yearsOfAge, 1, 1) - date(inYear, 1, 1)) then
  442.     return 1
  443.   else
  444.     return 0
  445.   end if
  446. end
  447.  
  448. on diffFactor DIFFICULTY
  449.   case DIFFICULTY of
  450.     1, 2:
  451.       return currentLevel(#diffVlow)
  452.     3, 4:
  453.       return currentLevel(#DIFFLOW)
  454.     5, 6:
  455.       return currentLevel(#DIFFMED)
  456.     7, 8:
  457.       return currentLevel(#DIFFHIGH)
  458.     9, 10:
  459.       return currentLevel(#diffVHigh)
  460.   end case
  461. end
  462.  
  463. on glassPrefix glassType
  464.   return string(glassType).char[1..3]
  465. end
  466.  
  467. on checkIfFlashWasHit me, pSpr
  468.   global gBarTopManager, gGaveIDcardHint, gGaveOrderHint, gGameLevel, gClickToIDorOrder
  469.   if pSpr.member.type <> #flash then
  470.     exit
  471.   end if
  472.   hitMe = hitTest(pSpr, the clickLoc)
  473.   wasDragging = draggingAnything()
  474.   if wasDragging and (the clickOn = me.spriteNum) then
  475.     replaceDraggingAnything()
  476.   end if
  477.   if hitMe = #normal then
  478.     if wasDragging then
  479.       replaceDraggingAnything()
  480.     end if
  481.     if bouncingOrRetreating(me) then
  482.       alertBeep()
  483.       exit
  484.     end if
  485.     lastActiveSlot = getActiveSlot(gBarTopManager)
  486.     if lastActiveSlot = me.pMyBarSlot then
  487.       newActiveCharacter = 0
  488.     else
  489.       newActiveCharacter = 1
  490.       makePatronActive(me.pMyBarSlot)
  491.     end if
  492.     if wasDragging then
  493.       replaceDraggingAnything()
  494.     else
  495.       if modifierDown() and inTestMode() then
  496.         characterLeft(me)
  497.       else
  498.         if not busy(me) then
  499.           if gGameLevel = 1 then
  500.             if not me.pAlreadyCarded then
  501.               if not gGaveIDcardHint then
  502.                 remindAboutID()
  503.               else
  504.                 if gClickToIDorOrder then
  505.                   card(me)
  506.                 end if
  507.               end if
  508.             else
  509.               if me.pStatus = #carded then
  510.                 if not gGaveOrderHint then
  511.                   remindToTakeOrder()
  512.                 else
  513.                   if gClickToIDorOrder then
  514.                     order(me)
  515.                   end if
  516.                 end if
  517.               end if
  518.             end if
  519.           end if
  520.           if not newActiveCharacter then
  521.             beckon(me)
  522.           end if
  523.         end if
  524.       end if
  525.     end if
  526.   else
  527.     if me.pMyBarSlot > 1 then
  528.       sendSprite(barSlotToSprite(me.pMyBarSlot - 1), #mouseUp)
  529.     end if
  530.   end if
  531. end
  532.  
  533. on floor input
  534.   if input = 0 then
  535.     return 0
  536.   else
  537.     if input > 0 then
  538.       return integer(input - 0.5)
  539.     else
  540.       return integer(input + 0.5)
  541.     end if
  542.   end if
  543. end
  544.